<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>JavascriptBridge Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">

    <script type="text/javascript"></script>
</head>

<body>
<h1>
    JavascriptBridge Demo
</h1>
<script type="text/javascript">
        //注册事件监听
       //注册事件监听
       function connectWebViewJavascriptBridge(callback) {
           if (window.WebViewJavascriptBridge) {
               callback(WebViewJavascriptBridge)
           } else {
               document.addEventListener(
                   'WebViewJavascriptBridgeReady'
                   , function() {
                       callback(WebViewJavascriptBridge)
                   },
                   false
               );
           }
       }

        //注册回调函数，第一次连接时调用 初始化函数
       connectWebViewJavascriptBridge(function(bridge) {
            //初始化
           bridge.init(function(message, responseCallback) {
               var data = {
                   'Javascript Responds': 'Wee!'
               };
               responseCallback(data);
           });
       });

        //发送消息给安卓
         function testClick() {
          //调用java中的方法   submitFromWeb是方法名
            window.WebViewJavascriptBridge.callHandler(
               'submitFromWeb'
               , "ucity://release/dynamic"
               , function(responseData) {
                    alert(responseData)
               }
           );
       }
</script>

<button id="show" onclick="testClick();">
    打开
</button>
<br/>

</body>
</html>
